(function (factory) {
  // Packaging/modules magic dance
  var L;
  if (typeof define === 'function' && define.amd) {
    // AMD
    define(['leaflet'], factory);
  } else if (typeof module !== 'undefined') {
    // Node/CommonJS
    L = require('leaflet');
    module.exports = factory(L);
  } else {
    // Browser globals
    if (typeof window.L === 'undefined') {
      throw new Error('Leaflet must be loaded first');
    }
    factory(window.L);
  }
}(function (L) {
  'use strict';

  L.Control.Buslayer = (function () {

    var Buslayer = L.Control.extend({
      options: {
        position: 'topright',
        _divedit:null,
        _divcont:null,
        _checkboxCctvSite:null,
        _checkboxVtsSubCenter:null,
        _checkboxVtsRadarSt:null,
        _checkboxSosOrganization:null,
        _checkboxSosFlyDevice:null,
		    _checkboxEmWarehouse:null,
		    _aclose:null
      },
      //初始化参数
      initialize: function (options) {
        L.Util.extend(this.options, options);
      },
      onAdd: function (map) {
        this._map = map;
        //创建一个class为leaflet-control-clegend的div，作用整体容器，可以同 this._container.appendChild 向此容器中添加任何内容
        this._container = L.DomUtil.create('div', 'leaflet-control-Buslayer');

        //创建自己的内容
        this._divedit=L.DomUtil.create('div', 'leaflet-draw-control-edit-div'); //leaflet-draw-control-edit-div 可以随便写，因为后面会通过sytle设置样式
        this._divedit.style="width:29px;height:29px;border:2px solid #889ebe; background-color:#ffffff;text-align:center;vertical-align:middle;";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divedit);
        this._divedivimg.style="width:24px;height:24px;margin-top:3px;background-image:url('/static/js/draw-lib/images/map_contro_bus_layers.png')";
        L.DomEvent.addListener(this._divedit, 'click', this.ShowToolBar, this);

        //搜救力量div
        this._divcont_sjll=L.DomUtil.create('div', 'leaflet-draw-control-cont-div');
        this._divcont_sjll.style="height:29px;border-top:1px solid #889ebe;border-left:1px solid #889ebe;border-right:1px solid #889ebe;border-bottom:0px solid #889ebe; background-color:#ffffff;text-align:right;vertical-align:middle;";
        L.DomUtil.addClass(this._divcont_sjll,"leaflet-draw-control-hide");

        this._checkboxSosOrganization=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_sjll);
        this._checkboxSosOrganization.style= "margin-right:5px;margin-left:5px;";
        this._checkboxSosOrganization.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_sjll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/SosOrg.png')";
        this.labelt3=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_sjll);
        this.labelt3.innerHTML="搜救机构";
        L.DomEvent.addListener(this._checkboxSosOrganization, 'click', this.SosOrganization, this);

        this._checkboxZysjcb=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_sjll);
        this._checkboxZysjcb.style= "margin-right:5px;margin-left:5px;";
        this._checkboxZysjcb.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_sjll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/zy_sos_hip.png')";
        this.labelZysjcb=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_sjll);
        this.labelZysjcb.innerHTML="专业救助船舶";

        this._checkboxShllsjcb=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_sjll);
        this._checkboxShllsjcb.style= "margin-right:5px;margin-left:5px;";
        this._checkboxShllsjcb.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_sjll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/shlljz_ship.png')";
        this.labelShllsjcb=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_sjll);
        //this.labelShllsjcb.style= "width:103px;";
        this.labelShllsjcb.innerHTML="社会力量救助船舶";

        this._checkboxSosFlyDevice=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_sjll);
        this._checkboxSosFlyDevice.style= "margin-right:5px;margin-left:5px;";
        this._checkboxSosFlyDevice.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_sjll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/SosFlyDevice.png')";
        this.labelt4=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_sjll);
        this.labelt4.innerHTML="救助飞行器";
        L.DomEvent.addListener(this._checkboxSosFlyDevice, 'click', this.SosFlyDevice, this);
        //搜救力量结束

        //溢油力量div
        this._divcont_yyll=L.DomUtil.create('div', 'leaflet-draw-control-cont-div');
        this._divcont_yyll.style="padding-right:35px;height:29px;line-height:29px;border-top:0px solid #889ebe;border-left:1px solid #889ebe;border-right:1px solid #889ebe;border-bottom:0px solid #889ebe; background-color:#ffffff;text-align:right;vertical-align:middle;";
        L.DomUtil.addClass(this._divcont_yyll,"leaflet-draw-control-hide");

        this._checkboxYyyjcb=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_yyll);
        this._checkboxYyyjcb.style= "margin-right:5px;margin-left:5px;";
        this._checkboxYyyjcb.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_yyll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/emship.png')";
        this.labelYyyjcb=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_yyll);
        //this.labelYyyjcb.style= "width:103px;";
        this.labelYyyjcb.innerHTML="溢油应急船舶";

        this._checkboxEmWarehouse=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_yyll);
        this._checkboxEmWarehouse.style= "margin-right:5px;margin-left:5px;";
        this._checkboxEmWarehouse.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_yyll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/EmWarehouse.png')";
        this.labelt5=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_yyll);
        this.labelt5.innerHTML="溢油应急库";
        L.DomEvent.addListener(this._checkboxEmWarehouse, 'click', this.EmWarehouse, this);
        //溢油力量div

        //执法力量div
        this._divcont_zfll=L.DomUtil.create('div', 'leaflet-draw-control-cont-div');
        this._divcont_zfll.style="padding-right:35px;height:29px;line-height:29px;border-top:0px solid #889ebe;border-left:1px solid #889ebe;border-right:1px solid #889ebe;border-bottom:0px solid #889ebe; background-color:#ffffff;text-align:right;vertical-align:middle;";
        L.DomUtil.addClass(this._divcont_zfll,"leaflet-draw-control-hide");

        this._checkboxZfjg=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfll);
        this._checkboxZfjg.style= "margin-right:5px;margin-left:5px;";
        this._checkboxZfjg.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/zfjg.png')";
        this.labelZfjg=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfll);
        this.labelZfjg.innerHTML="执法机构";

        this._checkboxZfry=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfll);
        this._checkboxZfry.style= "margin-right:5px;margin-left:5px;";
        this._checkboxZfry.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfll);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/zfry.png')";
        this.labelZfry=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfll);
        this.labelZfry.style= "width:103px;";
        this.labelZfry.innerHTML="执法人员";
        //执法力量div

        //执法装备div
        this._divcont_zfzb=L.DomUtil.create('div', 'leaflet-draw-control-cont-div');
        this._divcont_zfzb.style="padding-right:35px;height:29px;border-top:0px solid #889ebe;border-left:1px solid #889ebe;border-right:1px solid #889ebe;border-bottom:1px solid #889ebe; background-color:#ffffff;text-align:right;vertical-align:middle;";
        L.DomUtil.addClass(this._divcont_zfzb,"leaflet-draw-control-hide");

        this._checkboxVtsSubCenter=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfzb);
        this._checkboxVtsSubCenter.style= "margin-right:5px;margin-left:5px;";
        this._checkboxVtsSubCenter.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfzb);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/VtsSubCenter.png')";
        this.labelt1=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfzb);
        this.labelt1.innerHTML="VTS分中心";
        L.DomEvent.addListener(this._checkboxVtsSubCenter, 'click', this.VtsSubCenter, this);

        this._checkboxVtsRadarSt=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfzb);
        this._checkboxVtsRadarSt.style= "margin-right:5px;margin-left:5px;";
        this._checkboxVtsRadarSt.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfzb);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/VtsRadarSt.png')";
        this.labelt2=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfzb);
        this.labelt2.innerHTML="VTS雷达";
        L.DomEvent.addListener(this._checkboxVtsRadarSt, 'click', this.VtsRadarSt, this);

        this._checkboxCctvSite=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfzb);
        this._checkboxCctvSite.style= "margin-right:5px;margin-left:5px;";
        this._checkboxCctvSite.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfzb);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/CctvSite.png')";
        this.labelt=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfzb);
        this.labelt.innerHTML="CCTV站点";
        this.labelt.style="height:29px;line-height:29px;text-align:center;vertical-align:middle;";
        L.DomEvent.addListener(this._checkboxCctvSite, 'click', this.CctvSite, this);

        this._checkboxZfct=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfzb);
        this._checkboxZfct.style= "margin-right:5px;margin-left:5px;";
        this._checkboxZfct.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfzb);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/zfct.png')";
        this.labelZfct=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfzb);
        this.labelZfct.innerHTML="执法船艇";

        this._checkboxZfcl=L.DomUtil.create('input', 'leaflet-draw-control-checkbox',this._divcont_zfzb);
        this._checkboxZfcl.style= "margin-right:5px;margin-left:5px;";
        this._checkboxZfcl.type="checkbox";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont_zfzb);
        this._divedivimg.style="width:20px;height:14px;margin-top:3px;background-image:url('/static/css/images/mapobj/zfcl.png')";
        this.labelZfcl=L.DomUtil.create('label', 'leaflet-draw-control-checlboxlabel',this._divcont_zfzb);
        this.labelZfcl.style= "width:103px;";
        this.labelZfcl.innerHTML="执法车辆";
        //执法装备div

        this._aclose=L.DomUtil.create('a', 'leaflet-draw-control-a',this._divcont_sjll);
        this._aclose.href = '#';
        this._aclose.style= "line-height:29px;height:29px;width:20px;margin-right:5px;margin-left:5px;";
        this._aclose.innerHTML="返回";
        L.DomEvent.addListener(this._aclose, 'click', this.HideToolBar, this);

        this._container.appendChild(this._divedit);
        this._container.appendChild(this._divcont_sjll);
        this._container.appendChild(this._divcont_yyll);
        this._container.appendChild(this._divcont_zfll);
        this._container.appendChild(this._divcont_zfzb);

        //返回
        return this._container;
      },
      onRemove: function (map) {

      },
      ShowToolBar:function () {
        L.DomUtil.addClass(this._divedit,"leaflet-draw-control-hide");
        L.DomUtil.removeClass(this._divcont_sjll,"leaflet-draw-control-hide");
        L.DomUtil.removeClass(this._divcont_yyll,"leaflet-draw-control-hide");
        L.DomUtil.removeClass(this._divcont_zfll,"leaflet-draw-control-hide");
        L.DomUtil.removeClass(this._divcont_zfzb,"leaflet-draw-control-hide");
      },
      HideToolBar:function () {
        L.DomUtil.addClass(this._divcont_sjll,"leaflet-draw-control-hide");
        L.DomUtil.addClass(this._divcont_yyll,"leaflet-draw-control-hide");
        L.DomUtil.addClass(this._divcont_zfll,"leaflet-draw-control-hide");
        L.DomUtil.addClass(this._divcont_zfzb,"leaflet-draw-control-hide");
        L.DomUtil.removeClass(this._divedit,"leaflet-draw-control-hide");
      },
      CctvSite:function () {
        let checkstate=this._checkboxCctvSite.checked;
        let param={"bustype":"CctvSite","show":checkstate};
        this._map.fire('onShowHideBusLayer',param);
      },
      VtsSubCenter:function () {
        let checkstate=this._checkboxVtsSubCenter.checked;
        let param={"bustype":"VtsSubCenter","show":checkstate};
        this._map.fire('onShowHideBusLayer',param);
      },
      VtsRadarSt:function () {
        let checkstate=this._checkboxVtsRadarSt.checked;
        let param={"bustype":"VtsRadarSt","show":checkstate};
        this._map.fire('onShowHideBusLayer',param);
      },
      SosOrganization:function () {
        let checkstate=this._checkboxSosOrganization.checked;
        let param={"bustype":"SosOrganization","show":checkstate};
        this._map.fire('onShowHideBusLayer',param);
      },
      SosFlyDevice:function () {
        let checkstate=this._checkboxSosFlyDevice.checked;
        let param={"bustype":"SosFlyDevice","show":checkstate};
        this._map.fire('onShowHideBusLayer',param);
      },
	    EmWarehouse:function () {
        let checkstate=this._checkboxEmWarehouse.checked;
        let param={"bustype":"EmWarehouse","show":checkstate};
        this._map.fire('onShowHideBusLayer',param);
      }
    });

    return Buslayer;
  })();

  L.control.buslayer = function (options) {
    return new L.Control.Buslayer(options);
  };
}));
